package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.CollegePageDto;
import com.grademaster.entity.Colleges;
import com.grademaster.service.CollegesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/colleges")
@Api(tags = "学院相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class CollegesController {

    @Autowired
    private CollegesService collegesService;

    @ApiOperation("获取所有学院信息")
    @GetMapping("/getAllColleges")
    public R getAllColleges() {
        return collegesService.getAllColleges();
    }

    @ApiOperation("获取所有学院分页信息")
    @GetMapping("/getAllCollegesByPage")
    public R getAllCollegesByPage(CollegePageDto collegePageDto) {
        return collegesService.getAllCollegesByPage(collegePageDto);
    }

    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(CollegePageDto collegePageDto){
        return collegesService.exportExcel(collegePageDto);
    }

    @ApiOperation("添加或修改学院")
    @PostMapping("/addorEditCollege")
    public R addOrEditCollege(@RequestBody Colleges colleges) {
        return collegesService.addorEditCollege(colleges);
    }

    @ApiOperation("删除学院")
    @DeleteMapping("/deleteCollege/{collegeId}")
    public R deleteCollege(@PathVariable("collegeId") String collegeId) {
        return collegesService.deleteCollege(collegeId);
    }
}
